<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="SuperTablePage">
    </ex_super_table_page>
  </div>
</template>

<script>
import business_function from "@/common/business_function"
import SuperTablePageFunction from '@/mixin/super-table-page-function';

export default {
  name: "title_stock_detail_query",
  title: 'title_stock_detail_query',
  mixins: [SuperTablePageFunction],
  components: {},
  data() {
    return {
      option: {
        //搜索框内容
        search: {
          //搜索框内容，key为搜索字段，label为标签提示
          model: [

            { label: "label_customer", key: "customerId", type: 'common_customer_choose', },
            { label: "label_sku", key: "skuId", type: 'sku_selec_input', },
            {label: "label_business_type", key: "bizType", type: 'select', enum: 'BizTypeEnum'},
            {
              label: "label_putaway_time",
              key: "putawayTimeStart",
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
            {
              label: "-",
              key: "putawayTimeEnd",
              type: 'date-picker',
              attrs: { type: "datetime" },
            },
          ],
        },
        actionExtra: [
          {
            label: 'label_export', click: this.exportExcel
          },
        ],
        table: {
          url: "/wms-api/stock/StockQueryRpc/stockContainerQuery.json",
          attrs: {},
          model: [
            {
              key: 'skuOnlyCode', label: 'label_sku_only_code',
              attrs: {
                formatter: (r, c, v, i) => r.skuId < 0 ? "——" : v
              }
            },
            {
              key: 'skuName', label: 'label_sku_name_cn',
              attrs: {
                formatter: (r, c, v, i) => r.skuId < 0 ? "——" : v
              }
            },
            {
              key: 'customerCode', label: 'label_srm_api_request_customer_code',
            },
            {
              key: 'customerName', label: 'label_customer_name',
            },
            {
              key: 'putawayTime', label: 'label_putaway_time', formatter: (r, c, v, i) => this.$dateFormat(v)
            },
            {
              key: 'areaCode', label: 'label_warehouse_area_code',
            },
            {
              key: 'locationCode', label: 'label_warehouse_location',
            },
            {
              key: 'containerCode', label: 'label_container_code',
            },
            {
              key: 'subContainerCode', label: 'label_sub_container_code',
            },
            {
              key: 'bizType', label: 'label_business_type', 'width': 120, 'show-overflow-tooltip': true,
              formatter: (r, c, v, i) => this.$enumShow(v, "BizTypeEnum")
            },
            {
              key: 'freezeQty', label: 'label_frozen_count',
            },
            {
              key: 'lockQty', label: 'label_lock_count',
            },
            {
              key: 'usableQty', label: 'label_usable_count',
            },
            {
              key: 'totalQty', label: 'label_sum',
            },
            {
              key: 'skuVolume', label: 'label_sku_volume',
            },
            {
              key: 'putawayTime', label: '库龄(day)',
              formatter: (r, c, v, i) => {

                let now = new Date().getTime()
                let l1 = now - r.putawayTime;
                let day = l1 / (24 * 60 * 60 * 1000);

                if (day < 1) {
                  day = 1;
                }
                return parseInt(day);
              }
            }

          ],

        }
        ,

      },
    }
  },
  methods: {
    exportExcel() {
      const searchParams = this.$refs.SuperTablePage.getSearchData()
      business_function.confirmOperateBaseSelectOrForm.call(this, {
        data: searchParams,
        model: this.option.search.model,
        callback: (selection, data) => {
          let params = data
          this.$functionCommon({
            url: "/wms-api/stock/StockQueryRpc/stockContainerExportExcel.json",
            data: params, type: 'form',
          })
        }
      })


    },
  }

}
</script>

<style scoped></style>
